package factory;

import data.student;
import data.user;
import dataBase.userBaseConnector;
import PO.UserPO;

public class userFactory {
	public student studentMaker(String[] info){
		return new student(info[0],info[1],info[2],info[3],info[4],info[5]);
	}
	
	public user userMaker(String[] info){
		return new user(info[0],info[1],info[2]);
	}
	
	public user userMaker(UserPO u){
		return new user(u.getId(),u.getCode(),u.getRole());
	}

	public UserPO userPOMaker(user u){
		userBaseConnector ubc = new userBaseConnector();
		String depart = null;
		String name = null;
		String password = u.getPassword();
		String role = u.getRole();
		if(u.getRole().equals("5")){
			String[] info = ubc.queryStudentInfo(u.getId());
			name = info[1];
			depart = info[2];
			
		}
		else{
			String[] info = ubc.queryTeacherInfo(u.getId());
			name = info[1];
			depart = info[3];
		}	
		return new UserPO(u.getId(),u.getPassword(),name,u.getRole(),depart);
	}
//	student studentMaker(String id){
//		userBaseConnector ubc = new userBaseConnector();
//		String[] info = ubc.queryStudentInfo(id);
//		return  studentMaker(info);
//	}
//	
//	UserPO userMaker(String id){
//		userBaseConnector ubc = new userBaseConnector();
//		String[] info = ubc.queryLog(id);
//		return userMaker(info);
//	}
}
